#!/bin/bash
# 删除源安装文件
rm -rf /opt/module/maven/apache-maven-3.6.3/

URL=https://dlcdn.apache.org/maven/maven-3/3.9.3/binaries/apache-maven-3.9.3-bin.zip
source ../linux/download_unzip.sh "maven" $URL
echo "maven脚本中： mv $File_HOME/conf/settings.xml $File_HOME/conf/settings.xml.bak"
mv $File_HOME/conf/settings.xml $File_HOME/conf/settings.xml.bak
# 仓库位置
MAVEN_REPO=$REPO_PATH/maven_repo
# 仓库不存在创建
if [ ! -d "$MAVEN_REPO" ]; then
    mkdir -p $MAVEN_REPO
fi



# 修改本地仓库位置，及阿里镜像下载地址
sudo cat >$File_HOME/conf/settings.xml<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>$MAVEN_REPO</localRepository>
  <pluginGroups></pluginGroups>
  <proxies></proxies>
  <servers></servers>
  <mirrors>
		<mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
	  </mirror>
  </mirrors>
  <profiles></profiles>
</settings>
EOF
# 配置 MAVEN 环境变量
if (( 0 == `cat /etc/profile | grep MAVEN_HOME | wc -l` )); then
sudo cat >>/etc/profile<<EOF

#===== 配置 MAVEN_HOME 环境变量 =====
MAVEN_HOME=$File_HOME
PATH=\$PATH:\$MAVEN_HOME/bin
export MAVEN_HOME PATH
EOF
fi

# 刷新环境变量
source /etc/profile

$File_HOME/bin/mvn --version
